package p_103

import java.io.BufferedInputStream
import java.io.InputStream
import java.io.InputStreamReader
import java.io.Reader
import java.net.URL

/**
 * URL 的API
 */
class SourceViewer {
    val url = "https://www.baidu.com/"
    fun doSome() {
        try {
            val myUrl = URL(url)
            println("myUrl.getContent-->${myUrl.content}")
            val connection = myUrl.openConnection()

            val io: InputStream = connection.getInputStream()
            val bio = BufferedInputStream(io)
            val reader: Reader = InputStreamReader(bio)
            var i = 0
            if ((reader.read() != -1).also { i = reader.read() }) {
                println(i.toChar())
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }

    }

}